package com;
public class Graph<T> {
    private java.lang.Object vertexMap;
    public <Vertex> boolean addVertex(T label, double cost) {
        Vertex vertex = vertexMap.get(label);
        if (vertex != null) {
            //如果图中已经存在该节点，则更新权值，返回false
            vertex.setCost(cost);
            return false;
        }
        //如果图中不存在该节点，则插入，返回true
        vertex = new Vertex<T>(label, cost);
        vertexMap.put(label, vertex);
        return true;
    }
    public <Vertex> int getEdgeCount() {
        Iterator<Vertex<T>> iterator = getVertexIterator();
        int count = 0;
        while (iterator.hasNext()) {
            Vertex<T> vertex = iterator.next();
            count = count + vertex.getEdgeCount();
        }
        return count;
    }

    public int getEdgeCount(T label) {
        Vertexvertex = vertexMap.get(label);
        if (vertex == null) {
            return -1;
        }
        return vertex.getEdgeCount();
    }

    public Iterator<Edge> getEdgeIterator(T label) {
        Vertex vertex = vertexMap.get(label);
        if (vertex == null) {
            //如果图中没有这个顶点，返回null
            return null;
        }
        return vertex.getEdgeIterator();
    }


}